<tr style="background-color: rgba(0,0,0,0.1);">
  <td rel="popover" data-img="api/taskimg.php?supertask=[[set.getVal('taskWrapperId')]]&x=1200&y=6">&nbsp;</td>
  <td>
    [[set.getVal('supertaskName')]]
    [[Util::tickdone([[set.getVal('tasksDone')]], [[set.getVal('numTasks')]])]]
    {{IF [[set.getVal('isActive')]] == 1 && [[set.getVal('tasksDone')]] < [[set.getVal('numTasks')]]}}
      <i class="fas fa-spinner fa-spin"></i>
    {{ENDIF}}
  </td>
  <td>
    {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_HASHLIST_ACCESS]])]]}}
      <a href="hashlists.php?id=[[set.getVal('hashlistId')]]">[[set.getVal('hashlistName')]]</a>
    {{ELSE}}
      [[set.getVal('hashlistName')]]
    {{ENDIF}}
    {{IF [[set.getVal('hashlistSecret')]] == 1}}
      <span class="fas fa-lock" aria-hidden="true"></span>
    {{ENDIF}}
    {{IF [[set.getVal('hashCount')]] == [[set.getVal('hashlistCracked')]]}}
      [[Util::tickdone(1, 1)]]
    {{ELSE}}
      [[Util::tickdone(0, 1)]]
    {{ENDIF}}
  </td>
  <td>&nbsp;</td>
  <td class='num'>
    {{IF [[set.getVal('cracked')]] > 0}}
      [[set.getVal('cracked')]]
    {{ENDIF}}
  </td>
  <td class='num'>
    {{IF [[set.getVal('numAssignments')]] > 0}}
      [[set.getVal('numAssignments')]]
    {{ENDIF}}
  </td>
  <td style='min-width: 130px' data-sort="[[set.getVal('priority')]]">
    {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_TASK_ACCESS]])]]}}
      <form class="form-inline" action="tasks.php" method="POST">
        <input type='hidden' name='action' value='[[$DTaskAction::SET_SUPERTASK_PRIORITY]]'>
        <input type="hidden" name="supertaskId" value="[[set.getVal('taskWrapperId')]]">
        <input type="hidden" name="csrf" value="[[csrf]]">
        <input type="text" class='form-control' style='width: 60px;' name="priority" size="4" value="[[set.getVal('priority')]]" title="Priority">&nbsp;&nbsp;
        <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' data-toggle="tooltip" data-placement="top" title="Set"><i class="fas fa-save" aria-hidden="true"></i></button>
      </form>
    {{ELSE}}
      [[set.getVal('priority')]]
    {{ENDIF}}
  </td>
  <td style='min-width: 130px' data-sort="[[set.getVal('maxAgents')]]">
    {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_TASK_ACCESS]])]]}}
      <form class="form-inline" action="tasks.php" method="POST">
        <input type='hidden' name='action' value='[[$DTaskAction::SET_SUPERTASK_MAX_AGENTS]]'>
        <input type="hidden" name="supertaskId" value="[[set.getVal('taskWrapperId')]]">
        <input type="hidden" name="csrf" value="[[csrf]]">
        <input type="text" class='form-control' style='width: 60px;' name="maxAgents" size="4" value="[[set.getVal('maxAgents')]]" title="Max agents">&nbsp;&nbsp;
        <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' data-toggle="tooltip" data-placement="top" title="Set"><i class="fas fa-save" aria-hidden="true"></i></button>
      </form>
    {{ELSE}}
      [[set.getVal('maxAgents')]]
    {{ENDIF}}
  </td>
  <td style='min-width: 120px'>
    {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_TASK_ACCESS]])]]}}
      <form class="float-right mx-1" action="tasks.php" method="POST" onSubmit="if (!confirm('Really delete supertask [[set.getVal('taskWrapperId')]]?')) return false;">
        <input type="hidden" name="action" value="[[$DTaskAction::DELETE_SUPERTASK]]">
        <input type="hidden" name="supertaskId" value="[[set.getVal('taskWrapperId')]]">
        <input type="hidden" name="csrf" value="[[csrf]]">
        <button type="submit" class='btn btn-danger' data-toggle="tooltip" data-placement="top" title="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button>
      </form>
      {{IF ![[showArchived]]}}
        <form class="float-right mx-1" action="tasks.php" method="POST" onSubmit="if (!confirm('Really archive task [[set.getVal('taskWrapperId')]]?')) return false;">
          <input type="hidden" name="action" value="[[$DTaskAction::ARCHIVE_SUPERTASK]]">
          <input type="hidden" name="supertaskId" value="[[set.getVal('taskWrapperId')]]">
          <input type="hidden" name="csrf" value="[[csrf]]">
          <button type="submit" class='btn btn-warning' data-toggle="tooltip" data-placement="top" title="Archive Supertask"><i class="fas fa-archive" aria-hidden="true"></i></button>
        </form>
      {{ENDIF}}
    {{ENDIF}}
    {{IF [[set.getVal('taskType')]] == 1}}
      <form class="float-right mx-1">
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#task[[set.getVal('taskWrapperId')]]"><i class="fas fa-info-circle" aria-hidden="true"></i></button>
      </form>
    {{ENDIF}}

    <div class="modal fade" id="task[[set.getVal('taskWrapperId')]]" tabindex="-1" role="dialog" aria-labelledby="subtasks" aria-hidden="true">
      <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Subtasks (Hashlist '[[set.getVal('hashlistName')]]')</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="card">
              <div class="table-nonfluid">
                <table class="table table-bordered table-subtask-border table-sm" style="margin-bottom: 0;" id="subtasks[[set.getVal('taskWrapperId')]]">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Name</th>
                      <th>Dispatched / Searched</th>
                      <th>Cracked</th>
                      <th>Agents</th>
                      <th>Priority</th>
                      <th>Max agents</th>
                      <th>Action</th>
                    </tr>
                  </thead>
                  <tbody>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
      var loaded = [];
      $(document).ready(function () {
        $('#task[[set.getVal("taskWrapperId")]]').on('shown.bs.modal', function () {
          // load data if needed
          if (!loaded['[[set.getVal("taskWrapperId")]]']) {
            $.ajax({
              url: 'ajax/get_subtasks.php?taskWrapperId=[[set.getVal("taskWrapperId")]]&showArchived=[[showArchived]]',
              success: function (result) {
                $('#subtasks[[set.getVal("taskWrapperId")]]').find('tbody').empty().append(result);
                $('#subtasks[[set.getVal("taskWrapperId")]]').DataTable({
                  pageLength: 25,
                  "order": [ [6, 'desc'], [0, 'asc'] ],
                  "columnDefs": [
                    { "orderable": false, "targets": [2, 7] },
                    { "orderable": true, "targets": [0, 1, 3, 4, 5, 6] }
                  ]
                });
                setTimeout(
                  function(){
                    $('#subtasks[[set.getVal("taskWrapperId")]]').DataTable().columns.adjust().responsive.recalc();
                  },
                  300
                );
                loaded['[[set.getVal("taskWrapperId")]]'] = true;
                $('td[rel=popover]').popover({
                  html: true,
                  trigger: 'hover',
                  container: 'body',
                  content: function () { return '<img style="width: 100%; height: 6px; padding: 0px;" src="' + $(this).data('img') + '">'; }
                });
                $('[data-toggle="tooltip"]').tooltip();
              }
            });
          }
        });
      });
    </script>
  </td>
</tr>
